package com.sunday.common.reactor;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Slf4j
public class SubscribeUtils {

    private static int id = 0;

//    public static String uuid() {
//        return UUID.randomUUID().toString().replaceAll("-", "");
//    }

    public static int uuid() {
        return id++;
    }

    public static void subscribe(Mono mono) {
        Object id = uuid();
        log.info("[{}]================================", id);
        mono.subscribe(i -> log.info("[{}] subscribe : {}", id, i),
                error -> log.error("[{}] error : {}", id, error.toString()),
                () -> log.info("[{}] Done ==============", id));
    }

    public static void subscribe(Flux flux) {
        Object id = uuid();
        log.info("[{}]=================================", id);
        flux.subscribe(i -> log.info("[{}] subscribe : {}", id, i),
                error -> log.error("[{}] error : {}", id, error.toString()),
                () -> log.info("[{}] Done ==============", id));
    }

}
